/* 
 * File:   simplex.h
 * Purpose:
 * Contains structure and procedure definitions for Simplex Method
 * Author: abhi
 *
 * Created on September 18, 2011, 3:28 PM
 */

#ifndef SIMPLEX_H
#define	SIMPLEX_H

#define MAX_ITERATIONS 50

#ifdef	__cplusplus
extern "C" {
#endif
    
    typedef enum e_solution { OPTIMAL, UNBOUNDED, SUBOPTIMAL, INFEASIBLE } solution;
    
    /* struct for entering columns */
    typedef struct s_enteringColumn {
        int columnIndex;
        int leavingRowIndex; /* one of the optimal rows*/
        rational cj_zj; /* criteria for column */
        rational theta; /* minimum +ve bi/yij */
    } enteringColumn;
    
    extern solution simplexProc(rational*** rationalMatrixWithArtVar, int rows, int cols, int** startingBasisVector, int* artificialVariableColumns, int numArtVar, rational** costVector);
    
    extern solution phaseI(rational*** rationalMatrix, int rows, int cols, int** startingBasisVector, int* artificialVariableColumns, int numArtVar);
    
    extern solution phaseII(rational*** rationalMatrix, int rows, int cols, int** startingBasisVector, rational** costVector);
    
    extern solution phaseIterations(rational*** rationalMatrix, int rows, int cols, int** startingBasisVector, rational** costVector);
    
    extern solution singleIteration(rational*** rationalMatrix, int rows, int cols, int** basisVector, rational** costVector, int** newBasisVector);
    
    extern void changeRationalMatrix(rational*** rationalMatrix, int rows, int cols, int enteringColumn, int leavingRow);
    
    extern void removeArtVarColumns(rational*** rationalMatrixWithArtVar, rational*** rationalMatrix, int* artificialVariableColumns, int numArtVar, int rows, int cols, int** basisVector);
    
    extern rational basisCostVectorPdt(int rank, int** basisVector, rational** costVector, rational*** rationalMatrix, int basisColumn);
    
    extern void getEnteringColumnVector(enteringColumn** enteringColumnVector, int size);
    
#ifdef	__cplusplus
}
#endif

#endif	/* SIMPLEX_H */

